home *** CD-ROM | disk | FTP | other *** search
/ Geek Games #12 / GEGA012.iso / Jogos de Azar / 1721-apuesten.swf / scripts / C_BalanceMashine.as < prev    next >
Text File  |  2006-01-17  |  4KB  |  182 lines

  1. _global.C_BalanceMashine = function()
  2. {
  3.    this.init();
  4.    this.drawBalance();
  5. };
  6. C_BalanceMashine.prototype = new MovieClip();
  7. C_BalanceMashine.prototype.init = function()
  8. {
  9.    this._x = Math.round(this._x);
  10.    this._y = Math.round(this._y);
  11.    this.comma_mc._visible = 0;
  12.    var o;
  13.    var t;
  14.    this.c_array = [];
  15.    this.c_array[0] = this.C1_mc;
  16.    this.c_array[1] = this.C2_mc;
  17.    var i = 0;
  18.    while(i < this.c_array.length)
  19.    {
  20.       t = this.c_array[i];
  21.       t._x = Math.round(t._x);
  22.       t._y = Math.round(t._y);
  23.       t.number_new = 0;
  24.       i++;
  25.    }
  26.    this.S4_mc.isComma = true;
  27.    this.d_array = [];
  28.    this.d_array[0] = this.S1_mc;
  29.    this.d_array[1] = this.S2_mc;
  30.    this.d_array[2] = this.S3_mc;
  31.    this.d_array[3] = this.S4_mc;
  32.    this.d_array[4] = this.S5_mc;
  33.    this.d_array[5] = this.S6_mc;
  34.    var i = 0;
  35.    while(i < this.d_array.length)
  36.    {
  37.       t = this.d_array[i];
  38.       t._x = Math.round(t._x);
  39.       t._y = Math.round(t._y);
  40.       t.number_new = 0;
  41.       i++;
  42.    }
  43. };
  44. C_BalanceMashine.prototype.addProperty("balance",function()
  45. {
  46.    return this._balance;
  47. }
  48. ,function(b)
  49. {
  50.    this._balance = b;
  51.    this.drawBalance();
  52. }
  53. );
  54. C_BalanceMashine.prototype.drawBalance = function()
  55. {
  56.    this.animTargets = 0;
  57.    var centes = String(Math.floor(this._balance * 100)).substr(-2);
  58.    if(centes.length < 2)
  59.    {
  60.       centes = "0" + centes;
  61.    }
  62.    var i = 0;
  63.    while(i < this.c_array.length)
  64.    {
  65.       this.drawNumber(this.c_array[i],centes.substr((i + 1) * -1,1));
  66.       i++;
  67.    }
  68.    var dollars = "       " + String(Math.floor(this._balance));
  69.    var i = 0;
  70.    while(i < this.d_array.length)
  71.    {
  72.       this.drawNumber(this.d_array[i],dollars.substr((i + 1) * -1,1));
  73.       i++;
  74.    }
  75. };
  76. C_BalanceMashine.prototype.drawNumber = function(targ, n)
  77. {
  78.    var number_new = n != " " ? Number(n) : 0;
  79.    var number_old = targ.number_new != " " ? targ.number_new : 0;
  80.    var a = targ.eventsArray = [];
  81.    if(targ.number_new == n || isNaN(number_new))
  82.    {
  83.       return undefined;
  84.    }
  85.    if(number_new == number_old)
  86.    {
  87.       if(n == " ")
  88.       {
  89.          a.push({event:"BACK",number_old:0,number_new:" "});
  90.       }
  91.       else
  92.       {
  93.          a.push({event:"FORWARD",number_old:" ",number_new:0});
  94.       }
  95.    }
  96.    else
  97.    {
  98.       var d;
  99.       var event;
  100.       var p = Math.abs(number_new - number_old) <= 5;
  101.       if(number_new > number_old)
  102.       {
  103.          if(p)
  104.          {
  105.             event = "FORWARD";
  106.             d = 1;
  107.          }
  108.          else
  109.          {
  110.             event = "BACK";
  111.             d = -1;
  112.          }
  113.       }
  114.       else if(!p)
  115.       {
  116.          event = "FORWARD";
  117.          d = 1;
  118.       }
  119.       else
  120.       {
  121.          event = "BACK";
  122.          d = -1;
  123.       }
  124.       if(targ.number_old == " ")
  125.       {
  126.          a.push({event:"FORWARD",number_old:" ",number_new:0});
  127.       }
  128.       var cur_number = number_old;
  129.       while(cur_number != number_new)
  130.       {
  131.          number_old = cur_number;
  132.          cur_number += d;
  133.          if(cur_number > 9)
  134.          {
  135.             cur_number = 0;
  136.          }
  137.          else if(cur_number < 0)
  138.          {
  139.             cur_number = 9;
  140.          }
  141.          a.push({event:event,number_old:number_old,number_new:cur_number});
  142.       }
  143.       if(n == " ")
  144.       {
  145.          a.push({event:"BACK",number_old:0,number_new:" "});
  146.       }
  147.    }
  148.    if(a.length)
  149.    {
  150.       this.animTargets = this.animTargets + 1;
  151.       Conv.stop();
  152.    }
  153.    if(targ.stoped)
  154.    {
  155.       this.onEvent(targ);
  156.    }
  157. };
  158. C_BalanceMashine.prototype.onEvent = function(targ)
  159. {
  160.    var a = targ.eventsArray;
  161.    if(a.length == 0)
  162.    {
  163.       targ.stoped = true;
  164.       if(--this.animTargets <= 0)
  165.       {
  166.          Conv.play();
  167.       }
  168.       return undefined;
  169.    }
  170.    targ.stoped = false;
  171.    var e = a.shift();
  172.    targ.number_old = e.number_old;
  173.    targ.number_new = e.number_new;
  174.    targ.gotoAndPlay(e.event);
  175.    if(targ.isComma)
  176.    {
  177.       this.comma_mc._visible = e.number_new != " ";
  178.    }
  179. };
  180. Object.registerClass("C_BalanceMashine",C_BalanceMashine);
  181. ASSetPropFlags(_global,"C_BalanceMashine",131);
  182.